package com.putprize



import java.io.File
import com.typesafe.config._

import scala.io.Source
import scala.collection.mutable.ArrayBuffer

import com.putprize.percy.PyotrStream

import org.apache.log4j.PropertyConfigurator

object Pyotr extends App {
  
    println("Hello Pyotr")
    
    PropertyConfigurator.configure("log4j.properties")
    
    val c = ConfigFactory.parseFile(new File("Percy.properties"))
    
//    val x = c.getInt("CPU_NUM")
//    import collection.parallel.ForkJoinTasks.defaultForkJoinPool._
//    println(getParallelism)
//    setParallelism(x)
//    println(getParallelism)
    
    val mode = c.getString("MODE")
    
    if (mode == "one"){
      val locationSize = c.getString("LOCATION_SIZE")
      val locationData = c.getString("LOCATION_DATA")
      val locationCountT = c.getString("LOCATION_CT")
      val locationCountV = c.getString("LOCATION_CV")
      val maxIter = c.getInt("MAX_ITER_NUM")
      val minConv = c.getDouble("MIN_CONVERGENCE")
      
      PyotrStream.runOne(locationSize, locationData, locationCountT, locationCountV,
                         maxIter,minConv)
    }
    
    if (mode == "stream"){
      val locationSize = c.getString("LOCATION_SIZE")
      val locationData = c.getString("LOCATION_DATA")
      
      val ROOT = c.getString("ROOT_TOPIC")
      
      val locationCT = c.getString("LOCATION_CT")
      val locationCV = c.getString("LOCATION_CV")
      
      val locationInit = c.getString("LOCATION_INIT")
      val init = c.getInt("INIT")
      
      val M = c.getInt("STREAM")
      
      val N = c.getInt("MAX_ITER_NUM")
      val I = c.getInt("ITER_NUM")
      val B = c.getInt("BATCH_SIZE")
      val T = c.getInt("SAVE_THETA")
      
      val we = c.getDouble("WEAK_SUPERVISION_WEIGHT")
      
      PyotrStream.runNew(locationSize, locationData, locationCT, locationCV, locationInit, 
          init, ROOT, I, M, B, N, T, we)
      
      //PyotrStream.run(locationSize, ns.toArray, locationCT, locationCV, ROOT1, ROOT2, saveN)
    }
    
    if (mode == "server") {
      val locationModelCT = c.getString("LOCATION_MODEL_CT")
      val locationModelCV = c.getString("LOCATION_MODEL_CV")
      val locationMeasure = c.getString("LOCATION_MEASURE")
      val serverPort = c.getInt("SERVER_PORT")
      val useMeasure = c.getBoolean("MEASURE")
      val docNum = c.getInt("DOC_NUM")
      val minValueScore = c.getDouble("MIN_VALUE_SCORE")
      
      PyotrServer.run(locationModelCT, locationModelCV, locationMeasure,
          docNum,useMeasure,minValueScore,serverPort)
    }
  

	
  
}

